#ifndef CAMERAMICROEPSILONPLUGIN_H
#define CAMERAMICROEPSILONPLUGIN_H

//llt.h必须放在qt头文件之前否则报错
#include <llt.h>
#include <QGenericPlugin>
#include <camera_interface.h>
#include <time.h>
#include <string>
#include <vector>
#include <iostream>

using namespace std;



#define MAX_INTERFACE_COUNT 6
#define MAX_RESOLUTION 6
#define MINIMUM_WAITE_TIME 714          //获取数据最短等待这么长的时间


class CameraMicroEpsilonPlugin : public QGenericPlugin,public camera_interface
{
    Q_OBJECT
#if QT_VERSION >= 0x050000
    Q_PLUGIN_METADATA(IID camera_interface_iid )
    Q_INTERFACES(camera_interface)
    Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QGenericPluginFactoryInterface" FILE "CameraMicroEpsilonPlugin.json")
#endif // QT_VERSION >= 0x050000

public:
    CameraMicroEpsilonPlugin(QObject *parent = nullptr);
    //QGenericPlugin必须实现的纯虚函数
    QObject* create(const QString& name, const QString &spec) override;
    //通信初始化 ip和端口号
    bool init( string ip , uint16_t port ) override;
    //反初始化，若检测断开连接之后可以调用此函数，并再次调用初始化
    bool dinit( void ) override;
    //获取通信参数
    bool get_com_para( string &ip , uint16_t &port ) override;
    //设置相机曝光
    bool set_exposure( uint32_t exposure ) override;
    //设置激光器模式
    //如果是LASER_DIGTAL_POWER模式，可以通过laser_power直接设置激光器功率
    bool set_laser_mode( _LASER_MODE laser_mode, uint32_t laser_power = 0 ) override;
    //设置传感器x轴分辨率
    //x_s轮廓x提取起点，x_end轮廓x提取终点
    virtual bool set_camera_x_resolution( uint32_t x_start , uint32_t x_end ) override;
    //设置传感器z方向视野起点和终点
    virtual bool set_camera_z_resolution( uint32_t z_start , uint32_t z_end ) override;
    //获取传感器x轴分辨率
    virtual bool get_camera_x_resolution( uint32_t &x_start , uint32_t &x_end ) override;
    //获取传感器z方向视野起点和终点
    virtual bool get_camera_z_resolution( uint32_t &z_start , uint32_t &z_end ) override;
    //设置传感器增益参数
    //scanControl未实现
    virtual bool set_camera_gain( uint32_t gain ) override;
    //获取激光器轮廓
    bool get_profiler( vector<double> &x,vector<double> &z ) override;
    //获取错误原因
    string get_error( void ) override;
    //清除错误
    bool clear_error( void ) override;
private:
    uint32_t resolution;
    std::vector<uint8_t> profile_buffer;
    TScannerType llt_type;
    uint32_t wait_time = 0;
    uint32_t m_nlasermode;
    uint32_t u_exposure_time = 0;
    uint32_t idle_time = 614;
    CInterfaceLLT *hLLT = nullptr;
    bool is_init = false;
};

#endif // CAMERAMICROEPSILONPLUGIN_H
